package com.zking.service.impl;

import com.zking.dao.BookDao;
import com.zking.pojo.Book;
import com.zking.pojo.Page;
import com.zking.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class BookServiceImpl implements BookService {
    @Autowired
    private BookDao bookDao;

    @Override
    public boolean add(Book book) {
        int i=bookDao.add(book);
        if(i>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean update(Book book) {
        int i=bookDao.update(book);
        if(i>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public boolean delete(Integer id) {
        int i=bookDao.delete(id);
        if(i>0){
            return true;
        }else{
            return false;
        }
    }

    @Override
    public Book getById(Integer id) {
        return bookDao.getById(id);
    }

    @Override
    public List<Book> getAll() {
        return bookDao.getAll();
    }

    @Override
    public List<Book> selectBywhere(Book book, Page page) {
        page.setCurrentPage((page.getCurrentPage()-1)*page.getPageSize());
        return bookDao.selectBywhere(book,page);
    }

   /* @Override
    public List<Book> selectBywhere(String name,Integer currentPage,Integer pageSize) {
        return bookDao.selectBywhere(name,(currentPage-1)*pageSize,pageSize);
    }*/
}
